package com.lan.schedule;

import static com.lan.schedule.MainActivity.getAlplaBitmap;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ReplacementSpan;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import androidx.core.content.FileProvider;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.concurrent.FutureTask;

class LinearGradientFontSpan extends ReplacementSpan {
    private int mSize;
    private int startColor;
    private int endColor;


    public LinearGradientFontSpan(int startColor, int endColor) {
        this.startColor = startColor;
        this.endColor = endColor;

    }

    @Override
    public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
        mSize = (int) (paint.measureText(text, start, end));

        //这段不可以去掉，字体高度没设置，可能出现draw（）方法没有被调用，如果你调用SpannableStringBuilder后append一个字符串，效果也是会出来，下面这段就不需要了
        // 原因详见https://stackoverflow.com/questions/20069537/replacementspans-draw-method-isnt-called
        Paint.FontMetricsInt metrics = paint.getFontMetricsInt();
        if (fm != null) {
            fm.top = metrics.top;
            fm.ascent = metrics.ascent;
            fm.descent = metrics.descent;
            fm.bottom = metrics.bottom;
        }

        return mSize;
    }

    @Override
    public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
        LinearGradient lg = new LinearGradient(0, 0, 0, paint.descent() - paint.ascent(),
                startColor,
                endColor,
                Shader.TileMode.REPEAT); //从上到下渐变
        paint.setShader(lg);

        canvas.drawText(text, start, end, x, y, paint);//绘制文字
    }

}

public class Main2Activity extends Activity {
    GradientDrawable.Orientation or[] = {GradientDrawable.Orientation.TL_BR, GradientDrawable.Orientation.BR_TL, GradientDrawable.Orientation.BL_TR, GradientDrawable.Orientation.TR_BL, GradientDrawable.Orientation.TOP_BOTTOM, GradientDrawable.Orientation.BOTTOM_TOP, GradientDrawable.Orientation.LEFT_RIGHT, GradientDrawable.Orientation.RIGHT_LEFT};
    final String[] m = {"左上—右下", "右下—左上", "左下—右上", "右上—左下", "上—下", "下—上", "左—右", "右—左"};
    GradientDrawable.Orientation or1 = or[5];
    int red, green, blue, index;
    final GradientDrawable drawable81 = new GradientDrawable();
    final GradientDrawable drawable71 = new GradientDrawable();
    final GradientDrawable drawable211 = new GradientDrawable();
    final GradientDrawable drawable212 = new GradientDrawable();
    final GradientDrawable drawable213 = new GradientDrawable();
    //    String st=getString(R.string.app_name);
    int top = 0;
    int now = 0;
    int dord[] = new int[6];

    public void fidod() {
        for (int i = 0; i < 6; i++) {
            dord[i] = 0;
        }
    }

    public void reads() {
        SharedPreferences nw_qq = getSharedPreferences("nowtop_xml", MODE_PRIVATE);
        String now2 = nw_qq.getString("now", "0");
        String top2 = nw_qq.getString("top", "0");
        now = Integer.parseInt(now2);
        top = Integer.parseInt(top2);
    }

    int loc[][][] = new int[6][3][4];
    int loc0[][][] = new int[6][3][4];
    int loc1[][][] = new int[4][3][4];
    int ifcolor[] = new int[6];
    int grcolor[] = new int[6];
    int grcolor0[] = new int[6];
    int flazjm=-9;
    String vpa;
    int colorcan[][] = new int[6][3];

    int fo = 0xff000000;
    int alp = 100;
    int sh = 0x55ffffff;
    int ba = 0xffff0000;
    int fla = -1;
    int fla1 = -9;
    int ba1 = 0xffff0000;
    int sh1 = 0x55ffffff;
    int fo1 = 0xff000000;

    public void fr() {
        colorcan[3][0] = 0xFFFFFFFF;
        colorcan[5][0] = 0x00FFFFFF;
        colorcan[0][1] = 0xFF000000;
        colorcan[0][2] = 0xFFFF0000;
        for (int i = 0; i < 6; i++) {
            ifcolor[i] = 0;
            grcolor[i] = 5;
            grcolor0[i] = grcolor[i];
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 4; k++) {
                    loc[i][j][k] = 0;
                    loc0[i][j][k] = 0;
                }
            }
        }
        loc[5][0][3] = 100;
        loc[5][1][3] = 100;
        loc[5][2][3] = 100;
        colorcan[5][0] = 0x00FFFFFF;
        colorcan[4][0] = 0xFFFFFFFF;
        colorcan[0][0] = 0xFF000000;
        colorcan[1][0] = 0xFF880000;
        colorcan[2][0] = 0x55ffffff;
        colorcan[3][0] = 0xffeeeeee;
    }

    public void startService() {
        Intent intent = new Intent(this, AlarmService.class);
        startService(intent);
    }

    public static SpannableStringBuilder getRadiusGradientSpan(String string, int startColor, int endColor) {
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(string);
        LinearGradientFontSpan span = new LinearGradientFontSpan(startColor, endColor);
        spannableStringBuilder.setSpan(span, 0, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spannableStringBuilder;

    }

    public void setloc(int a, int b) {
        loc[a][b][0] = ColorPickerViewa.vLocationLayoutParams.leftMargin;
        loc[a][b][1] = ColorPickerViewa.vLocationLayoutParams.topMargin;
        loc[a][b][2] = ColorPickerViewa.colorBarLayoutParams.topMargin;
        loc[a][b][3] = ColorPickerViewa.transBarLayoutParams.leftMargin;
    }

    public void setloc0(int a, int b) {
        loc0[a][b][0] = ColorPickerViewa.vLocationLayoutParams.leftMargin;
        loc0[a][b][1] = ColorPickerViewa.vLocationLayoutParams.topMargin;
        loc0[a][b][2] = ColorPickerViewa.colorBarLayoutParams.topMargin;
        loc0[a][b][3] = ColorPickerViewa.transBarLayoutParams.leftMargin;
    }
    ColorPickerViewa cpv;
    public void useloc0(int a, int b) {

        System.out.println(loc0[a][b][0] + loc0[a][b][1] + loc0[a][b][2] + loc0[a][b][3]);
        ColorPickerViewa.vLocationLayoutParams.leftMargin = loc0[a][b][0];
        ColorPickerViewa.vLocationLayoutParams.topMargin = loc0[a][b][1];
        ColorPickerViewa.colorBarLayoutParams.topMargin = loc0[a][b][2];
        ColorPickerViewa.transBarLayoutParams.leftMargin = loc0[a][b][3];
        ColorPickerViewa.vLocation.setLayoutParams(ColorPickerViewa.vLocationLayoutParams);
        ColorPickerViewa.vTransBar.setLayoutParams(ColorPickerViewa.transBarLayoutParams);
        ColorPickerViewa.vColorBar.setLayoutParams(ColorPickerViewa.colorBarLayoutParams);

    }

    public void useloc(int a, int b) {
        ColorPickerViewa.vLocationLayoutParams.leftMargin = loc[a][b][0];
        ColorPickerViewa.vLocationLayoutParams.topMargin = loc[a][b][1];
        ColorPickerViewa.colorBarLayoutParams.topMargin = loc[a][b][2];
        ColorPickerViewa.transBarLayoutParams.leftMargin = loc[a][b][3];
        ColorPickerViewa.vLocation.setLayoutParams(ColorPickerViewa.vLocationLayoutParams);
        ColorPickerViewa.vTransBar.setLayoutParams(ColorPickerViewa.transBarLayoutParams);
        ColorPickerViewa.vColorBar.setLayoutParams(ColorPickerViewa.colorBarLayoutParams);
    }

    public void saveloc() {
    }

    public void getloc() {
        try {
            String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file/thh";
            File file = new File(strFilePath, "thh1.txt");//在创建文件
            file.canRead();
            InputStream ff = null;
            ff = new FileInputStream(file);

            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(ff));

            for (int i = 0; i < 6; i++) {
                for (int j = 0; j < 3; j++) {
                    for (int k = 0; k < 4; k++) {
                        loc[i][j][k] = Integer.parseInt(bufferedReader.readLine());
                        loc0[i][j][k] = loc[i][j][k];
                    }
                }
            }
            ff.close();
            bufferedReader.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        //  System.out.println(fla+","+ba);
    }

    public void setc() {
        try {
            String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file/th";
            File file = new File(strFilePath, "th1.txt");//在创建文件
            file.canRead();
            InputStream ff = null;
            ff = new FileInputStream(file);

            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(ff));

            fla1 = Integer.parseInt(bufferedReader.readLine());
            alp = Integer.parseInt(bufferedReader.readLine());
            for (int y = 0; y < 6; y++) {
                ifcolor[y] = Integer.parseInt(bufferedReader.readLine());
                grcolor[y] = Integer.parseInt(bufferedReader.readLine());
                grcolor0[y] = grcolor[y];
                for (int x = 0; x < 3; x++) {
                    colorcan[y][x] = Integer.parseInt(bufferedReader.readLine());
                }
            }
            flazjm=Integer.parseInt(bufferedReader.readLine());
            vpa=bufferedReader.readLine();
            ff.close();
            bufferedReader.close();
            fla = fla1;
//            ba = ba1;
//            sh = sh1;
//            fo = fo1;
        } catch (Exception e) {
            e.printStackTrace();
        }
        //  System.out.println(fla+","+ba);
    }

    private static final int REQUEST_SELECT_PICTURE = 0x01;
    // 剪切后图像文件
    private Uri mDestinationUri;

    private Button cropBtn;
    private ImageView imageIv;
    String str1[] = new String[26];
    public int id2[] = {R.id.aa, R.id.ab, R.id.ac, R.id.ad, R.id.ae, R.id.af, R.id.ag, R.id.ah, R.id.ai, R.id.aj, R.id.ak, R.id.al, R.id.am, R.id.an, R.id.ao, R.id.ap, R.id.aq, R.id.ar, R.id.as, R.id.at, R.id.au, R.id.av, R.id.aw, R.id.ax, R.id.ay};
    TextView te1;
    GradientDrawable drawable2 = new GradientDrawable();
    GradientDrawable drawable3 = new GradientDrawable();
    GradientDrawable drawable4 = new GradientDrawable();
    GradientDrawable drawable5 = new GradientDrawable();
    GradientDrawable drawable6 = new GradientDrawable();
    GradientDrawable drawable7 = new GradientDrawable();
    GradientDrawable drawable8 = new GradientDrawable();
    GradientDrawable drawable9 = new GradientDrawable();
    GradientDrawable drawable10 = new GradientDrawable();
    GradientDrawable drawable11 = new GradientDrawable();
    GradientDrawable drawable12 = new GradientDrawable();
    GradientDrawable drawable13 = new GradientDrawable();
    GradientDrawable drawable14 = new GradientDrawable();
    GradientDrawable drawable15 = new GradientDrawable();
    GradientDrawable drawable16 = new GradientDrawable();
    GradientDrawable drawable17 = new GradientDrawable();
    GradientDrawable drawable18 = new GradientDrawable();
    GradientDrawable drawable19 = new GradientDrawable();
    GradientDrawable drawable20 = new GradientDrawable();
    GradientDrawable drawable21 = new GradientDrawable();
    GradientDrawable drawable22 = new GradientDrawable();
    GradientDrawable drawable23 = new GradientDrawable();
    GradientDrawable drawable24 = new GradientDrawable();
    GradientDrawable drawable25 = new GradientDrawable();
    GradientDrawable drawable26 = new GradientDrawable();
    GradientDrawable drawable1[] = {drawable2, drawable3, drawable4, drawable5, drawable6, drawable7, drawable8, drawable9, drawable10, drawable11, drawable12, drawable13, drawable14, drawable15, drawable16, drawable17, drawable18, drawable19, drawable20, drawable21, drawable22, drawable23, drawable24, drawable25, drawable26};
    float x1;
    float y1;

    public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {

        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);

        Canvas canvas = new Canvas(output);

        final int color = 0xff424242;

        final Paint paint = new Paint();

        final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

        final RectF rectF = new RectF(rect);

        final float roundPx = pixels;

        paint.setAntiAlias(true);

        canvas.drawARGB(0, 0, 0, 0);

        paint.setColor(color);

        canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

        canvas.drawBitmap(bitmap, rect, rect, paint);

        return output;

    }

    public int dpToPx(int dps) {
        return Math.round(getResources().getDisplayMetrics().density * dps);
    }

    Drawable dr;
    Drawable dr1;
    BitmapDrawable bbb;
    public static int f;
    Uri imageUri;
    private SeekBar seekbar;
    LinearLayout layout;
    EditText edit;
    TextView sharet;
    @SuppressLint({"WrongConstant", "WrongThread"})
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

            Window window = getWindow();

            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS

                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);

            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

            window.setStatusBarColor(Color.TRANSPARENT);

            window.setNavigationBarColor(Color.TRANSPARENT);
        }
        setContentView(R.layout.activity_main2);
        ImageView im1 = findViewById(R.id.back);
        ImageView im2 = findViewById(R.id.fore);
        fr();
        dr = getResources().getDrawable(R.drawable.radius_border1);
        dr1=getResources().getDrawable(R.drawable.rb3);
        te1 = findViewById(id2[0]);
        x1 = te1.getPaint().measureText(te1.getText().toString());//测量文本 宽度
        y1 = te1.getLineHeight();//测量文本 高度
        layout = (LinearLayout) findViewById(R.id.layout);
        File fileEx = this.getExternalFilesDir(null);
        String dir = fileEx.getAbsolutePath() + "/test_abc";
        if (!fileEx.exists()) { // 先根据路径创建文件夹
            fileEx.mkdirs();
        }
//        seekbar = findViewById(R.id.seekbar);
//        seekbar.setProgress(100);
//        seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
//            //seekbar绑定进度条的进度
//            @Override
//            public void onProgressChanged(SeekBar seekBar, int progress, boolean b) {
//                //设置水平进度条的进度由seekbar的当前进度填充
//                if(f==1);else{
//ma(progress);
//alp=progress;}
//            }
//            //拖动事件时触发
//            @Override
//            public void onStartTrackingTouch(SeekBar seekBar) {
//                if(fla==1);else
//fla=2;
//            }
//            //拖动停止时触发
//            @Override
//            public void onStopTrackingTouch(SeekBar seekBar) {
//                //判断进度条是否到达100%，达到即消失
//            }
//        });
        reads();
        setc();
        getloc();
        String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/files";
        File cacheFile = new File(strFilePath);
        // 上级文件不存在，进行文件夹的创建
        if (!cacheFile.exists()) { // 先根据路径创建文件夹
            cacheFile.mkdirs();
        }
        imageUri = Uri.fromFile(new File(strFilePath, "landx.png"));


        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        Button zjm=findViewById(R.id.zjm);
        zjm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                czjm();
//                Toast to = Toast.makeText(Main2Activity.this, "暂不支持，将在后期版本回归", Toast.LENGTH_LONG);
//                to.setGravity(Gravity.CENTER, 0, 0);
//                to.show();
            }
        });
        sharet=findViewById(R.id.sharecodetext);
        Button zjmco=findViewById(R.id.zjmco);
        zjmco.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                set1(1);
                flazjm=8;
//                Toast to = Toast.makeText(Main2Activity.this, "暂不支持，将在后期版本回归", Toast.LENGTH_LONG);
//                to.setGravity(Gravity.CENTER, 0, 0);
//                to.show();
            }
        });
        Button temp=findViewById(R.id.temp);
        temp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intent, 55500);
            }
        });
        Button zj = findViewById(R.id.zj);
        zj.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cropFromGallerywid();
            }
        });
        drawable211.setShape(GradientDrawable.RECTANGLE);
        drawable211.setGradientType(GradientDrawable.RECTANGLE);
        drawable211.setCornerRadius(50);
        drawable212.setShape(GradientDrawable.RECTANGLE);
        drawable212.setGradientType(GradientDrawable.RECTANGLE);
        drawable212.setCornerRadius(50);
        drawable213.setShape(GradientDrawable.RECTANGLE);
        drawable213.setGradientType(GradientDrawable.RECTANGLE);
        drawable213.setCornerRadius(50);
        float[] f1 = {50f, 50f, 0f, 0f, 0f, 0f, 0f, 0f};
        float[] f2 = {0f, 0f, 50f, 50f, 0f, 0f, 0f, 0f};
        float[] f3 = {0f, 0f, 0f, 0f, 50f, 50f, 0f, 0f};
        float[] f4 = {0f, 0f, 0f, 0f, 0f, 0f, 50f, 50f};
        float[] f5 = {0f, 0f, 50f, 50f, 50f, 50f, 0f, 0f};
        float[] f6 = {50f, 50f, 0f, 0f, 0f, 0f, 50f, 50f};


        final GradientDrawable drawable3 = new GradientDrawable();
        drawable3.setShape(GradientDrawable.RECTANGLE);
        drawable3.setGradientType(GradientDrawable.RECTANGLE);
        drawable3.setCornerRadii(f1);
        drawable3.setColor(0xffffffff);
        drawable3.setStroke(3, 0xffeeeeee);
        final GradientDrawable drawable4 = new GradientDrawable();
        drawable4.setShape(GradientDrawable.RECTANGLE);
        drawable4.setGradientType(GradientDrawable.RECTANGLE);
        drawable4.setCornerRadii(f2);
        drawable4.setColor(0xffffffff);
        drawable4.setStroke(3, 0xffeeeeee);
        final GradientDrawable drawable5 = new GradientDrawable();
        drawable5.setShape(GradientDrawable.RECTANGLE);
        drawable5.setGradientType(GradientDrawable.RECTANGLE);
        drawable5.setCornerRadii(f3);
        drawable5.setColor(0xffffffff);
        drawable5.setStroke(3, 0xffeeeeee);
        final GradientDrawable drawable6 = new GradientDrawable();
        drawable6.setShape(GradientDrawable.RECTANGLE);
        drawable6.setGradientType(GradientDrawable.RECTANGLE);
        drawable6.setCornerRadii(f4);
        drawable6.setColor(0xffffffff);
        drawable6.setStroke(3, 0xffeeeeee);
        drawable71.setShape(GradientDrawable.RECTANGLE);
        drawable71.setGradientType(GradientDrawable.RECTANGLE);
        drawable71.setCornerRadii(f5);
        drawable71.setColor(0xffffffff);
        drawable71.setStroke(3, 0xffeeeeee);
        drawable81.setShape(GradientDrawable.RECTANGLE);
        drawable81.setGradientType(GradientDrawable.RECTANGLE);
        drawable81.setCornerRadii(f6);
        drawable81.setColor(0xffffffff);
        drawable81.setStroke(3, 0xffeeeeee);
        final Button bt1 = findViewById(R.id.b1);
        final Button bt2 = findViewById(R.id.b2);
        final Button bt3 = findViewById(R.id.b3);
        final Button bt4 = findViewById(R.id.b4);
        Button poc = findViewById(R.id.poc);
        edit = findViewById(R.id.edit);
//        try {
//            FileInputStream fileInputStream = openFileInput("test2.txt");
//            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
//            String stt= "";
//            String sttr= "";
//            while((stt=bufferedReader.readLine())!=null){
//                sttr=sttr+stt+"\n";
//            }
//            edit.setText(sttr);
//            fileInputStream.close();
//            bufferedReader.close();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        final String[] ba = new String[1];
        final byte[][] ba1 = new byte[1][];
        Handler handlero=new Handler(){

            @Override

            public void handleMessage(Message msg) {

                super.handleMessage(msg);

                if (msg.what==1) {

                    Bitmap bitmap=(Bitmap) msg.obj;

                    layout.setBackgroundDrawable(new BitmapDrawable(toRoundCorner(bitmap, 100)));

                }

            }

        };
        poc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int a= Integer.parseInt(String.valueOf(edit.getText()));
                String data = null;
                int resultcode = 0;
                ObjectMapper mapper = new ObjectMapper();

                FutureTask signUpTask = new FutureTask<>(new NetworkThread(a,"data",NetworkSettings.COLOR_GET));

                Thread thread = new Thread(signUpTask);

                thread.start();

                try{

                    ResponseBody body = mapper.readValue(String.valueOf(signUpTask.get()),ResponseBody.class);
                    resultcode=body.getCode();
                    Toast.makeText(getApplicationContext(),body.getCode() == 200 ? "获取成功" : "获取失败",Toast.LENGTH_SHORT).show();
                    data= (String) body.getData();
                }catch (Exception e){

                    e.printStackTrace();

                }
                if(resultcode==200){
                    System.out.println("jsbhsj");
                    int c = 0;
                    String strcolor[];
                    strcolor=data.split(":");
                    fla1 = Integer.parseInt(strcolor[c++]);
                    alp = Integer.parseInt(strcolor[c++]);
                    for (int y = 0; y < 6; y++) {
                        ifcolor[y] = Integer.parseInt(strcolor[c++]);
                        grcolor[y] = Integer.parseInt(strcolor[c++]);
                        grcolor0[y] = grcolor[y];
                        for (int x = 0; x < 3; x++) {
                            colorcan[y][x] = Integer.parseInt(strcolor[c++]);
                        }
                    }
                    flazjm=Integer.parseInt(strcolor[c++]);
                    vpa=strcolor[c++];
                    fla = fla1;

                    if (fla == 1) {
                        if (ifcolor[1] == 0)
                            drawable211.setColors(new int[] {colorcan[1][0],colorcan[1][0]});
                        else {
                            int[] colors = {colorcan[1][1], colorcan[1][2]};
                            drawable211.setColors(colors);
                            drawable211.setOrientation(or[grcolor[1]]);
                        }
                        layout.setBackgroundDrawable(drawable211);
                    } else if (fla == 2) {
                        String strPath = "http://43.139.192.56/colorimg/"+a+".jpg";
                        final String finalStrPath = strPath;
                        new Thread(new Runnable() {

                            @Override

                            public void run() {

                                try {

                                    URL url=new URL(finalStrPath);

                                    HttpURLConnection connection = (HttpURLConnection)

                                            url.openConnection();

                                    connection.setReadTimeout(50*1000);

                                    connection.setConnectTimeout(50*1000);

                                    connection.setDoInput(true);

//                    connection.setDoOutput(true);

//设置请求方式

                                    connection.setRequestMethod("GET");

                                    InputStream is = connection.getInputStream();

                                    String path=String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/files/landx.png";


//                                    String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/files";
//                                    File fil=   new File(strFilePath, "landx_download.png");
//                                    Uri uri = FileProvider.getUriForFile(Main2Activity.this, "com.lan.schedule.fileprovider", fil);



                                    File file=new File(path);

                                    BufferedInputStream bis=new BufferedInputStream(is);

                                    BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(file));

                                    byte [] by=new byte[1024];

                                    int len=0;

                                    while((len=bis.read(by))!=-1){

                                        bos.write(by, 0, len);

                                    }

                                    bos.flush();

                                    bos.close();

                                    bis.close();

                                    is.close();

                                    Bitmap bit= BitmapFactory.decodeFile(path);

                                    Message msg=handlero.obtainMessage();

                                    msg.what=1;

                                    msg.obj=bit;

                                    handlero.sendMessage(msg);

                                } catch (MalformedURLException e) {

                                    e.printStackTrace();

                                } catch (IOException e) {

                                    e.printStackTrace();

                                }
                                try {
                                    bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
                                } catch (FileNotFoundException e) {
                                    e.printStackTrace();
                                }
                                int src_w = bitmap.getWidth();
                                int src_h = bitmap.getHeight();
                                float scale_w1 = ((float) 340) / src_w;
                                float scale_h1 = ((float) 253) / src_h;
                                Matrix matrix1 = new Matrix();
                                matrix1.postScale(scale_w1, scale_h1);
                                Bitmap bihuanbmp1 = Bitmap.createBitmap(bitmap, 0, 0, src_w, src_h, matrix1,true);
                                File cf1 = new File(String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file", "lanbx.png");
                                FileOutputStream fos1 = null;
                                try {
                                    fos1 = new FileOutputStream(cf1);
                                } catch (FileNotFoundException e) {
                                    e.printStackTrace();
                                }
                                bihuanbmp1.compress(Bitmap.CompressFormat.PNG, 100, fos1);
                                try {
                                    fos1.close();
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                            }

                        }).start();
//                        Uri imageUri;
//                        imageUri = Uri.fromFile(new File(strFilePath, "landx.png"));
//                        try {
//                            bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
//                        } catch (FileNotFoundException e) {
//                            e.printStackTrace();
//                        }
////            bitmap = getAlplaBitmap(bitmap, alp);
//                        bbb = new BitmapDrawable(toRoundCorner(bitmap, 100));
//                        layout.setBackgroundDrawable(bbb);
                    } else {
                        layout.setBackgroundDrawable(bbb);
                    }
                    if (ifcolor[2] == 0) {
                        for (int i = 0; i < 25; i++) {
                            drawable1[i].setShape(GradientDrawable.RECTANGLE);
                            drawable1[i].setGradientType(GradientDrawable.RECTANGLE);
                            drawable1[i].setCornerRadius(15);
                            drawable1[i].setStroke(3, colorcan[3][0]);
                            drawable1[i].setColor(colorcan[2][0]);
                        }
                    } else {
                        int[] cs = {colorcan[2][1], colorcan[2][2]};
                        for (int i = 0; i < 25; i++) {
                            drawable1[i].setShape(GradientDrawable.RECTANGLE);
                            drawable1[i].setGradientType(GradientDrawable.RECTANGLE);
                            drawable1[i].setCornerRadius(15);
                            drawable1[i].setStroke(3, colorcan[3][0]);
                            drawable1[i].setColors(cs);
                            drawable1[i].setOrientation(or[grcolor[2]]);
                        }
                    }
                    for (int o = 1; o < 26; o++) {
                        te1 = findViewById(id2[o - 1]);
                        te1.setTextColor(colorcan[0][0]);
                        //layout.setTextViewText(id2[o-1],str1[o]);
                        //notificationLayoutExpanded.setTextColor(id2[o-1],0xFFFFFF);
                        if (str1[o].equals("")) {
                        } else {
                            //notificationLayoutExpanded.setImageViewResource(id1[o-1],R.drawable.radius_border);
                            te1.setBackground(drawable1[o - 1]);
                        }
                    }
                }








//                ba[0] = String.valueOf(edit.getText());
//                System.out.println(ba[0]);
//                String[] str = ba[0].split(" ");
//                int f7=0;
//                f7=Integer.parseInt(str[0]);
//                colorcan[0][0]= Integer.parseInt(str[1]);
//                int x=2;
//                for (int i = 1; i < 3; i++) {
//                    ifcolor[i]= Integer.parseInt(str[x]);
//                    x++;
//                    grcolor[i]=Integer.parseInt(str[x]);
//                    x++;
//                    for (int y = 0; y < 3; y++) {
//                        colorcan[i][y]= Integer.parseInt(str[x]);
//                        x++;
//                    }
//                }
//                colorcan[3][0]= Integer.parseInt(str[x]);
//                if (f7 == 1) {
//                    fla=1;
//                    if (ifcolor[1] == 0)
//                        drawable211.setColor(colorcan[1][0]);
//                    else {
//                        int[] colors = {colorcan[1][1], colorcan[1][2]};
//                        drawable211.setColors(colors);
//                        drawable211.setOrientation(or[grcolor[1]]);
//                    }
//                    layout.setBackgroundDrawable(drawable211);
//                }
//                for (int o = 1; o < 26; o++) {
//                    te1 = findViewById(id2[o - 1]);
//                    te1.setTextColor(colorcan[0][0]);}
//                if (ifcolor[2] == 0) {
//                    for (int i = 0; i < 25; i++) {
//                        drawable1[i].setShape(GradientDrawable.RECTANGLE);
//                        drawable1[i].setGradientType(GradientDrawable.RECTANGLE);
//                        drawable1[i].setCornerRadius(15);
//                        drawable1[i].setStroke(3, colorcan[3][0]);
//                        drawable1[i].setColor(colorcan[2][0]);
//                    }
//                } else {
//                    int[] cs = {colorcan[2][1], colorcan[2][2]};
//                    for (int i = 0; i < 25; i++) {
//                        drawable1[i].setShape(GradientDrawable.RECTANGLE);
//                        drawable1[i].setGradientType(GradientDrawable.RECTANGLE);
//                        drawable1[i].setCornerRadius(15);
//                        drawable1[i].setStroke(3, colorcan[3][0]);
//                        drawable1[i].setColors(cs);
//                        drawable1[i].setOrientation(or[grcolor[2]]);
//                    }
//                }
            }
        });
//        bt1.setBackground(drawable3);
//        bt2.setBackground(drawable4);
//        bt4.setBackground(drawable5);
//        bt3.setBackground(drawable6);
        final Drawable drawable = getResources().getDrawable(R.drawable.bg1);

        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;

        Bitmap bitmap = bitmapDrawable.getBitmap();
        bbb = new BitmapDrawable(toRoundCorner(bitmap, 20));
        if (ifcolor[4] == 0)
            drawable212.setColor(colorcan[4][0]);
        else {
            int[] colors = {colorcan[4][1], colorcan[4][2]};
            drawable212.setColors(colors);
            drawable212.setOrientation(or[grcolor[4]]);
        }
        im1.setImageDrawable(drawable212);
        if (ifcolor[5] == 0)
            drawable213.setColor(colorcan[5][0]);
        else {
            int[] colors = {colorcan[5][1], colorcan[5][2]};
            drawable213.setColors(colors);
            drawable213.setOrientation(or[grcolor[5]]);
        }
        im2.setImageDrawable(drawable213);
        if (fla == 1) {
            if (ifcolor[1] == 0)
                drawable211.setColor(colorcan[1][0]);
            else {
                int[] colors = {colorcan[1][1], colorcan[1][2]};
                drawable211.setColors(colors);
                drawable211.setOrientation(or[grcolor[1]]);
            }
            layout.setBackgroundDrawable(drawable211);
        } else if (fla == 2) {
            Uri imageUri;
            imageUri = Uri.fromFile(new File(strFilePath, "landx.png"));
            try {
                bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
//            bitmap = getAlplaBitmap(bitmap, alp);
            bbb = new BitmapDrawable(toRoundCorner(bitmap, 100));
            layout.setBackgroundDrawable(bbb);
        } else {
            layout.setBackgroundDrawable(bbb);
        }
        if (ifcolor[2] == 0) {
            for (int i = 0; i < 25; i++) {
                drawable1[i].setShape(GradientDrawable.RECTANGLE);
                drawable1[i].setGradientType(GradientDrawable.RECTANGLE);
                drawable1[i].setCornerRadius(15);
                drawable1[i].setStroke(3, colorcan[3][0]);
                drawable1[i].setColor(colorcan[2][0]);
            }
        } else {
            int[] cs = {colorcan[2][1], colorcan[2][2]};
            for (int i = 0; i < 25; i++) {
                drawable1[i].setShape(GradientDrawable.RECTANGLE);
                drawable1[i].setGradientType(GradientDrawable.RECTANGLE);
                drawable1[i].setCornerRadius(15);
                drawable1[i].setStroke(3, colorcan[3][0]);
                drawable1[i].setColors(cs);
                drawable1[i].setOrientation(or[grcolor[2]]);
            }
        }

        //layout.setBackground(drawable211);
        int j = 0;
        String name1[] = new String[50];
        String loc[] = new String[50];
        int week[][] = new int[50][30];
        int we[] = new int[50];
        int day[] = new int[50];
        int jie[] = new int[50];
        try {
            FileInputStream fileInputStream = openFileInput("test.txt");
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
            j = Integer.parseInt(bufferedReader.readLine());
            for (int i = 1; i < j; i++) {
                name1[i] = bufferedReader.readLine();
                loc[i] = bufferedReader.readLine();
                jie[i] = Integer.parseInt(bufferedReader.readLine());
                day[i] = Integer.parseInt(bufferedReader.readLine());
                we[i] = Integer.parseInt(bufferedReader.readLine());
                for (int p = 1; p <= we[i]; p++) {
                    week[i][p] = Integer.parseInt(bufferedReader.readLine());
                }
            }
            fileInputStream.close();
            bufferedReader.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        String date = null;
        try {
            String strFilePath1 = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file/th";
            File file = new File(strFilePath1, "date.txt");//在创建文件
            file.canRead();
            InputStream ff = null;
            ff = new FileInputStream(file);

            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(ff));
            date=bufferedReader.readLine();
            ff.close();
            bufferedReader.close();
//            ba = ba1;
//            sh = sh1;
//            fo = fo1;
        } catch (Exception e) {
            e.printStackTrace();
        }
        String eTime = date;
        long nd = 1000 * 24 * 60 * 60 * 7;// 一天的毫秒数
        long diff = 0;
        long wee = 0;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Date curDate = new Date(System.currentTimeMillis());
        String nowtime = simpleDateFormat.format(curDate);
        try {
            diff = simpleDateFormat.parse(nowtime).getTime() - simpleDateFormat.parse(eTime).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        wee = diff / nd + 1;// 计算周数
        //wee=2;
        for (int i = 1; i < 26; i++) {
            int fl = 0;
            int ji;
            ji = i / 5 + 1;
            if (i % 5 == 0) ji = ji - 1;
            int da;
            da = i % 5;
            if (da == 0) da = 5;
            outterLoop:
            for (int g = 1; g < j; g++) {

                if (day[g] - 1 == da && jie[g] == ji) {
                    for (int p = 1; p <= we[g]; p++) {
                        if (wee == week[g][p]) {
                            fl = 1;
                            str1[i] = name1[g] + loc[g];
                            break outterLoop;
                        }
                    }
                }
            }
            if (fl == 0) str1[i] = "";
        }
        if (ifcolor[0] == 0) {
            for (int o = 1; o < 26; o++) {
                te1 = findViewById(id2[o - 1]);
                te1.setText(str1[o]);
                te1.setTextColor(colorcan[0][0]);
                //layout.setTextViewText(id2[o-1],str1[o]);
                //notificationLayoutExpanded.setTextColor(id2[o-1],0xFFFFFF);
                if (str1[o].equals("")) {
                } else {
                    //notificationLayoutExpanded.setImageViewResource(id1[o-1],R.drawable.radius_border);
                    te1.setBackground(drawable1[o - 1]);
                }
            }
        } else {
            for (int o = 1; o < 26; o++) {
                te1 = findViewById(id2[o - 1]);
                te1.setText(getRadiusGradientSpan(str1[o], colorcan[0][1], colorcan[0][2]));        //layout.setTextViewText(id2[o-1],str1[o]);
                //notificationLayoutExpanded.setTextColor(id2[o-1],0xFFFFFF);
                if (str1[o].equals("")) {
                } else {
                    //notificationLayoutExpanded.setImageViewResource(id1[o-1],R.drawable.radius_border);
                    te1.setBackground(drawable1[o - 1]);
                }
            }
        }
        //final TextView tvTest = findViewById(R.id.tv_test);
        final TextView te = findViewById(R.id.aa);
        PopupWindow popupWindow;
        bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                set1(1);
            }
        });
        bt3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                set1(2);
            }
        });
        bt4.setOnClickListener((new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                set2(0);
            }
        }));
        Button bt5 = findViewById(R.id.bk);
        bt5.setOnClickListener((new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                set2(3);
            }
        }));
//        bt1.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                f = 1;
//                drawable3.setStroke(3, 0xff0000aa);
//                bt1.setTextColor(0xff000099);
//                drawable3.setColor(0x11000099);
//                p.setText("请选择背景颜色");
//                drawable4.setStroke(3, 0xffeeeeee);
//                bt2.setTextColor(0xff000000);
//                drawable4.setColor(0xffffffff);
//                drawable6.setStroke(3, 0xffeeeeee);
//                bt3.setTextColor(0xff000000);
//                drawable6.setColor(0xffffffff);
//                drawable5.setStroke(3, 0xffeeeeee);
//                bt4.setTextColor(0xff000000);
//                drawable5.setColor(0xffffffff);
//            }
//        });
//        bt2.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                f = 2;
//                fla = 2;
//                drawable4.setStroke(3, 0xff0000aa);
//                bt2.setTextColor(0xff000099);
//                drawable4.setColor(0x11000099);
//                p.setText("");
//                drawable3.setStroke(3, 0xffeeeeee);
//                bt1.setTextColor(0xff000000);
//                drawable3.setColor(0xffffffff);
//                drawable6.setStroke(3, 0xffeeeeee);
//                bt3.setTextColor(0xff000000);
//                drawable6.setColor(0xffffffff);
//                drawable5.setStroke(3, 0xffeeeeee);
//                bt4.setTextColor(0xff000000);
//                drawable5.setColor(0xffffffff);
//                cropFromGallery();
//            }
//        });
//        bt3.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                f = 3;
//                drawable6.setStroke(3, 0xff0000aa);
//                bt3.setTextColor(0xff000099);
//                drawable6.setColor(0x11000099);
//                p.setText("请选择阴影底色及透明度");
//                drawable3.setStroke(3, 0xffeeeeee);
//                bt1.setTextColor(0xff000000);
//                drawable3.setColor(0xffffffff);
//                drawable4.setStroke(3, 0xffeeeeee);
//                bt2.setTextColor(0xff000000);
//                drawable4.setColor(0xffffffff);
//                drawable5.setStroke(3, 0xffeeeeee);
//                bt4.setTextColor(0xff000000);
//                drawable5.setColor(0xffffffff);
//            }
//        });
//        bt4.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                f = 4;
//                drawable5.setStroke(3, 0xff0000aa);
//                bt4.setTextColor(0xff000099);
//                drawable5.setColor(0x11000099);
//                p.setText("请选择文字颜色");
//                drawable3.setStroke(3, 0xffeeeeee);
//                bt1.setTextColor(0xff000000);
//                drawable3.setColor(0xffffffff);
//                drawable4.setStroke(3, 0xffeeeeee);
//                bt2.setTextColor(0xff000000);
//                drawable4.setColor(0xffffffff);
//                drawable6.setStroke(3, 0xffeeeeee);
//                bt3.setTextColor(0xff000000);
//                drawable6.setColor(0xffffffff);
//            }
//        });
        Button can = findViewById(R.id.can);
        can.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Main2Activity.this.finish();
            }
        });
        Button ap = findViewById(R.id.appli);
        final int tem = 1;
        ap.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int top1 = top + 1;
                SharedPreferences.Editor tnxml = getSharedPreferences("nowtop_xml", MODE_PRIVATE).edit();
                tnxml.putString("top", String.valueOf(top1));
                tnxml.putString("now", String.valueOf(top1));
                tnxml.apply();
                String data = null;
                data = fla + "\n" + alp + "\n";
                for (int y = 0; y < 6; y++) {
                    data = data + ifcolor[y] + "\n" + grcolor[y] + "\n";
                    for (int x = 0; x < 3; x++) {
                        data = data + colorcan[y][x] + "\n";
                    }
                }
                data =data+flazjm+"\n"+vpa+"\n";

//                ObjectMapper mapper = new ObjectMapper();
//
//                FutureTask signUpTask = new FutureTask<>(new NetworkThread(202020,data,NetworkSettings.COLOR_ADD));
//
//                Thread thread = new Thread(signUpTask);
//
//                thread.start();
//
//                try{
//
//                    ResponseBody body = mapper.readValue(String.valueOf(signUpTask.get()),ResponseBody.class);
//
//                    Toast.makeText(getApplicationContext(),body.getCode() == 200 ? "注册成功" : "注册失败",Toast.LENGTH_SHORT).show();
//
//                }catch (Exception e){
//
//                    e.printStackTrace();
//
//                }


//                ObjectMapper mapper = new ObjectMapper();
//
//                FutureTask signUpTask = new FutureTask<>(new NetworkThread(202020,"data",NetworkSettings.COLOR_GET));
//
//                Thread thread = new Thread(signUpTask);
//
//                thread.start();
//
//                try{
//
//                    ResponseBody body = mapper.readValue(String.valueOf(signUpTask.get()),ResponseBody.class);
//
//                    Toast.makeText(getApplicationContext(),body.getCode() == 200 ? "注册成功" : "注册失败",Toast.LENGTH_SHORT).show();
//data= (String) body.getData();
//                }catch (Exception e){
//
//                    e.printStackTrace();
//
//                }


                String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file/th";
                File cacheFile = new File(strFilePath);
                // 上级文件不存在，进行文件夹的创建
                if (!cacheFile.exists()) { // 先根据路径创建文件夹
                    cacheFile.mkdirs();
                }
                String filename = "th1.txt";

                File file = new File(strFilePath, filename);//在创建文件
                boolean createResult = false;
                try {
                    if (file.exists()) {
                        file.delete();
                    }
                    createResult = file.createNewFile();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                file.canWrite();
                OutputStream ff = null;
                try {
                    ff = new FileOutputStream(file);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
                byte[] szBuf = data.getBytes();
                try {
                    ff.write(szBuf);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                try {
                    ff.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                appp();

                startService();
                MyAppliacation.getInstance().getHandler().sendEmptyMessage(1);
                Main2Activity.this.finish();
            }
        });
    }

    public void appp() {
        int top1 = top + 1;
        String data1 = "";
        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 4; k++) {
                    data1 = data1 + loc[i][j][k] + "\n";
                }
            }
        }
        String strFilePath1 = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file/thh";
        File cacheFile1 = new File(strFilePath1);
        // 上级文件不存在，进行文件夹的创建
        if (!cacheFile1.exists()) { // 先根据路径创建文件夹
            cacheFile1.mkdirs();
        }
        String filename1 = "thh1.txt";

        File file1 = new File(strFilePath1, filename1);//在创建文件
        boolean createResult1 = false;
        try {
            if (file1.exists()) {
                file1.delete();
            }
            createResult1 = file1.createNewFile();
        } catch (Exception e) {
            e.printStackTrace();
        }
        file1.canWrite();
        OutputStream ff1 = null;
        try {
            ff1 = new FileOutputStream(file1);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        byte[] szBuf1 = data1.getBytes();
        try {
            ff1.write(szBuf1);
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            ff1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public String getRealFilePath(final Uri uri) {

        if (null == uri)
            return null;

        final String scheme = uri.getScheme();

        String data = null;

        if (scheme == null) {
            data = uri.getPath();
        } else if (ContentResolver.SCHEME_FILE.equals(scheme)) {
            data = uri.getPath();
        } else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) {

            Cursor cursor = getContentResolver().query(uri, new String[]{MediaStore.Images.ImageColumns.DATA}, null, null, null);

            if (null != cursor) {
                if (cursor.moveToFirst()) {
                    int index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
                    if (index > -1) {
                        data = cursor.getString(index);
                    }
                }
                cursor.close();
            }
        }
        return data;
    }
    public Uri getImageContentUri(File imageFile) {

        String filePath = imageFile.getAbsolutePath();

        Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[]{MediaStore.Images.Media._ID},
                MediaStore.Images.Media.DATA + "=? ",
                new String[]{filePath}, null);

        if (cursor != null && cursor.moveToFirst()) {
            int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID));
            Uri baseUri = Uri.parse("content://media/external/images/media");
            return Uri.withAppendedPath(baseUri, "" + id);
        } else {
            if (imageFile.exists()) {
                ContentValues values = new ContentValues();
                values.put(MediaStore.Images.Media.DATA, filePath);
                return getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
            } else {
                return null;
            }
        }
    }

    Bitmap bitmap;
    private final static int SELECT_PIC = 0x123;
    private  void minote(){

    }
    private  void getcrzjm(Uri uri1){
        String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/files";
        File fil=   new File(strFilePath, "landxzjm.png");
        Uri uri = FileProvider.getUriForFile(this, "com.lan.schedule.fileprovider", fil);

        Intent intent = new Intent();
        intent.setAction("com.android.camera.action.CROP");//Pick an item from the data
        intent.setDataAndType(uri1,"image/*");//从所有图片中进行选择
        intent.putExtra("crop", "true");//设置为裁切
        intent.putExtra("aspectX", 9);//裁切的宽比例
        intent.putExtra("aspectY", 20);//裁切的高比例
        intent.putExtra("outputX", 1080);//裁切的宽度
        intent.putExtra("outputY", 2400);//裁切的高度
        intent.putExtra("scale", true);//支持缩放
        intent.putExtra("return-data", false);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);//将裁切的结果输出到指定的Uri
        intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//裁切成的图片的格式
        intent.putExtra("noFaceDetection", true); // no face detection
        List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        for (ResolveInfo resolveInfo : resInfoList) {
            //我用的小米手机 packageName 得到的是：com.miui.gallery
            String packageName = resolveInfo.activityInfo.packageName;
            grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
            //注意不是 getPackageName()！！ getPackageName()得到的是app的包名
//            grantUriPermission(getPackageName(), cropUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }
        ComponentName componentName = intent.resolveActivity(getPackageManager());
        if (componentName != null) {
            startActivityForResult(intent, 8717);
        }
    }
    private  void getcr(Uri uri1){
        String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/files";
        File fil=   new File(strFilePath, "landx.png");
//        String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file";
//        File file = new File(strFilePath, "ll.png");//在创建文件
        Uri uri = FileProvider.getUriForFile(this, "com.lan.schedule.fileprovider", fil);

        Intent intent = new Intent();
        intent.setAction("com.android.camera.action.CROP");//Pick an item from the data
//        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION|Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        intent.setDataAndType(uri1,"image/*");//从所有图片中进行选择
        intent.putExtra("crop", "true");//设置为裁切
        intent.putExtra("aspectX", 344);//裁切的宽比例
        intent.putExtra("aspectY", 256);//裁切的高比例
        intent.putExtra("outputX", 2016);//裁切的宽度
        intent.putExtra("outputY", 1500);//裁切的高度
        intent.putExtra("scale", true);//支持缩放
        intent.putExtra("return-data", false);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);//将裁切的结果输出到指定的Uri
        intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//裁切成的图片的格式
        intent.putExtra("noFaceDetection", true); // no face detection
        List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        for (ResolveInfo resolveInfo : resInfoList) {
            //我用的小米手机 packageName 得到的是：com.miui.gallery
            String packageName = resolveInfo.activityInfo.packageName;
            grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
            //注意不是 getPackageName()！！ getPackageName()得到的是app的包名
//            grantUriPermission(getPackageName(), cropUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }
        ComponentName componentName = intent.resolveActivity(getPackageManager());
        if (componentName != null) {
            startActivityForResult(intent, SELECT_PIC);
        }
    }
    private  void czjm(){
        Intent inl=new Intent(Intent.ACTION_PICK,null);
        inl.setDataAndType(MediaStore.Images.Media.INTERNAL_CONTENT_URI,"image/*");
        startActivityForResult(inl,8716);
    }
    private void cropFromGallery() {
        String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/files";
        File fil=   new File(strFilePath, "landx.png");
//        String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file";
//        File file = new File(strFilePath, "ll.png");//在创建文件
        Uri uri = FileProvider.getUriForFile(this, "com.lan.schedule.fileprovider", fil);
        Intent inl=new Intent(Intent.ACTION_PICK,null);
        inl.setDataAndType(MediaStore.Images.Media.INTERNAL_CONTENT_URI,"image/*");
//        inl.putExtra(MediaStore.EXTRA_OUTPUT, uri);//将裁切的结果输出到指定的Uri
//        inl.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//裁切成的图片的格式
//        inl.putExtra("noFaceDetection", true); // no face detection
        startActivityForResult(inl,8715);
        // TODO Auto-generated method stub
//        String stri= String.valueOf(imageUri);
//        System.out.println(stri);
//System.out.println(uri);
//        Intent intent = new Intent();
//        intent.setAction("com.android.camera.action.CROP");//Pick an item from the data
//        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION|Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
//        intent.setDataAndType(uri,"image/*");//从所有图片中进行选择
////        intent.putExtra("crop", "true");//设置为裁切
////        intent.putExtra("aspectX", 344);//裁切的宽比例
////        intent.putExtra("aspectY", 256);//裁切的高比例
////        intent.putExtra("outputX", 344);//裁切的宽度
////        intent.putExtra("outputY", 256);//裁切的高度
////        intent.putExtra("scale", true);//支持缩放
////        intent.putExtra("return-data", false);
//        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);//将裁切的结果输出到指定的Uri
//        intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//裁切成的图片的格式
//        intent.putExtra("noFaceDetection", true); // no face detection
//        startActivityForResult(intent, SELECT_PIC);
    }

    final AlertDialog[] dlg = new AlertDialog[5];

    public void set1(final int aa) {
        f = 1;
        final int[] ff1 = {0};
        dlg[0] = new AlertDialog.Builder(Main2Activity.this).create();
        dlg[0].show();//显示对话框
        Window window = dlg[0].getWindow();//获取对话框窗口
        window.setGravity(Gravity.BOTTOM);//设置对话框显示剧中的位置
        if (aa == 1) window.setContentView(R.layout.xct1);
        else
            window.setContentView(R.layout.xct);//设置对话框布局
        window.setBackgroundDrawable(dr);
        WindowManager.LayoutParams params = dlg[0].getWindow()
                .getAttributes();
//        params.dimAmount = 0.0f;
        Display display = getWindowManager().getDefaultDisplay();
        params.width = (int) (display.getWidth());
//                params.y=MainActivity.dpToPx(50);
        dlg[0].getWindow().setAttributes(params);
        if (aa == 1) {
            Button img = window.findViewById(R.id.img);
            img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    cropFromGallery();
                }
            });

        }
        Button b1 = window.findViewById(R.id.dan);
        b1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                set2(aa);
            }
        });
        Button b2 = window.findViewById(R.id.gr);
        b2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final int[] cs = {colorcan[1][0], colorcan[1][0]};
                final int[] cs1 = {colorcan[2][0], colorcan[2][0]};
                dlg[2] = new AlertDialog.Builder(Main2Activity.this).create();
                dlg[2].show();//显示对话框
                dlg[2].setOnCancelListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialogInterface) {
                        if (ff1[0] == 0) {
                            switch (aa) {
                                case 1:
                                    if (fla == 1) {
                                        if (ifcolor[1] == 0) {
                                            layout.setBackground(drawable211);
                                            drawable211.setColors(cs);
                                        } else {
                                            int cs[] = {colorcan[1][1], colorcan[1][2]};
                                            layout.setBackground(drawable211);
                                            drawable211.setColors(cs);
                                            drawable211.setOrientation(or[grcolor[1]]);
                                        }
                                    } else if (fla == 2) {
                                        Uri imageUri;
                                        String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/files";

                                        imageUri = Uri.fromFile(new File(strFilePath, "landx.png"));
                                        try {
                                            bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
                                        } catch (FileNotFoundException e) {
                                            e.printStackTrace();
                                        }
//                                        bitmap = getAlplaBitmap(bitmap, alp);
                                        bbb = new BitmapDrawable(toRoundCorner(bitmap, 100));
                                        layout.setBackgroundDrawable(bbb);
                                    } else {
                                        layout.setBackgroundDrawable(bbb);
                                    }
                                    break;
                                case 2:
                                    if (ifcolor[2] == 0) {
                                        for (int o = 1; o < 26; o++) {
                                            if (str1[o].equals("")) {
                                            } else {
                                                drawable1[o - 1].setColors(cs1);
                                            }
                                        }
                                    } else {
                                        int cs2[] = {colorcan[2][1], colorcan[2][2]};
                                        for (int o = 1; o < 26; o++) {
                                            if (str1[o].equals("")) {
                                            } else {
                                                drawable1[o - 1].setColors(cs2);
                                                drawable1[o - 1].setOrientation(or[grcolor[2]]);
                                            }
                                        }
                                    }
                                    break;
                                case 0:
//                                LinearGradient topToBottomLG = new LinearGradient(0, 0, 0, y1,color, 0xFF00FFFF, Shader.TileMode.REPEAT);//从上到下渐变
                                    if (ifcolor[0] == 0) {
                                        for (int o = 1; o < 26; o++) {
                                            if (str1[o].equals("")) {
                                            } else {
                                                te1 = findViewById(id2[o - 1]);
                                                te1.setTextColor(colorcan[0][0]);
                                            }
                                        }
                                    } else {
                                        for (int o = 1; o < 26; o++) {
                                            if (str1[o].equals("")) {
                                            } else {
                                                te1 = findViewById(id2[o - 1]);
//                                        te1.getPaint().setShader(topToBottomLG);
                                                te1.setText(getRadiusGradientSpan(str1[o], colorcan[0][1], colorcan[0][2]));
                                                //  te1.invalidate();
//                                        te1.setTextColor(color);
                                            }
                                        }
                                    }
                                    break;
                            }
                        }
                    }
                });
                final int[] rf = {1};
                Window window = dlg[2].getWindow();//获取对话框窗口
                window.setGravity(Gravity.BOTTOM);//设置对话框显示剧中的位置
                window.setContentView(R.layout.ct1);//设置对话框布局
                window.setBackgroundDrawable(dr);
                WindowManager.LayoutParams params = dlg[2].getWindow()
                        .getAttributes();
                Display display = getWindowManager().getDefaultDisplay();
                params.width = (int) (display.getWidth());
//                        params.width=dpToPx(360);
                params.dimAmount = 0.0f;
                final int[] ff = {0};
                final int[] c1 = new int[2];
                c1[0] = colorcan[aa][1];
                c1[1] = colorcan[aa][2];
                ArrayAdapter<String> adapter;
                dlg[2].getWindow().setAttributes(params);
                useloc(aa, 1);
                int y = dpToPx(240);
                //  onProgressChanged(100-((loc[aa][1][2]*100)/y));
//                System.out.println(yyy);
                System.out.println(111);
                RadioButton r = window.findViewById(R.id.f1);
                r.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        or1 = or[0];
                        grcolor0[aa] = 0;
                        if (aa == 1) drawable211.setOrientation(or1);
                        else {
                            for (int o = 1; o < 26; o++) {
                                if (str1[o].equals("")) {
                                } else {
                                    drawable1[o - 1].setOrientation(or1);
                                }
                            }
                        }
                    }
                });
                RadioButton r1 = window.findViewById(R.id.f2);
                r1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        or1 = or[1];
                        grcolor0[aa] = 1;
                        if (aa == 1) drawable211.setOrientation(or1);
                        else {
                            for (int o = 1; o < 26; o++) {
                                if (str1[o].equals("")) {
                                } else {
                                    drawable1[o - 1].setOrientation(or1);
                                }
                            }
                        }
                    }
                });
                RadioButton r2 = window.findViewById(R.id.f3);
                r2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        or1 = or[2];
                        grcolor0[aa] = 2;
                        if (aa == 1) drawable211.setOrientation(or1);
                        else {
                            for (int o = 1; o < 26; o++) {
                                if (str1[o].equals("")) {
                                } else {
                                    drawable1[o - 1].setOrientation(or1);
                                }
                            }
                        }
                    }
                });
                RadioButton r3 = window.findViewById(R.id.f4);
                r3.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        or1 = or[3];
                        grcolor0[aa] = 3;
                        if (aa == 1) drawable211.setOrientation(or1);
                        else {
                            for (int o = 1; o < 26; o++) {
                                if (str1[o].equals("")) {
                                } else {
                                    drawable1[o - 1].setOrientation(or1);
                                }
                            }
                        }
                    }
                });
                RadioButton r4 = window.findViewById(R.id.f5);
                r4.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        or1 = or[4];
                        grcolor0[aa] = 4;
                        if (aa == 1) drawable211.setOrientation(or1);
                        else {
                            for (int o = 1; o < 26; o++) {
                                if (str1[o].equals("")) {
                                } else {
                                    drawable1[o - 1].setOrientation(or1);
                                }
                            }
                        }
                    }
                });
                RadioButton r5 = window.findViewById(R.id.f6);
                r5.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        or1 = or[5];
                        grcolor0[aa] = 5;
                        if (aa == 1) drawable211.setOrientation(or1);
                        else {
                            for (int o = 1; o < 26; o++) {
                                if (str1[o].equals("")) {
                                } else {
                                    drawable1[o - 1].setOrientation(or1);
                                }
                            }
                        }
                    }
                });
                RadioButton r6 = window.findViewById(R.id.f7);
                r6.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        or1 = or[6];
                        grcolor0[aa] = 6;
                        if (aa == 1) drawable211.setOrientation(or1);
                        else {
                            for (int o = 1; o < 26; o++) {
                                if (str1[o].equals("")) {
                                } else {
                                    drawable1[o - 1].setOrientation(or1);
                                }
                            }
                        }
                    }
                });
                RadioButton r7 = window.findViewById(R.id.f8);
                r7.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        or1 = or[7];
                        grcolor0[aa] = 7;
                        if (aa == 1) drawable211.setOrientation(or1);
                        else {
                            for (int o = 1; o < 26; o++) {
                                if (str1[o].equals("")) {
                                } else {
                                    drawable1[o - 1].setOrientation(or1);
                                }
                            }
                        }
                    }
                });
                RadioButton r11 = window.findViewById(R.id.r1);
                r11.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        rf[0] = 1;
                    }
                });
                RadioButton r12 = window.findViewById(R.id.r2);
                r12.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        rf[0] = 2;
                    }
                });
                RadioButton r13 = window.findViewById(R.id.r3);
                r13.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        rf[0] = 3;
                    }
                });
//                       Spinner spinner = (Spinner) window.findViewById(R.id.sp);
//                        Field popup = null;
//                        try {
//                            popup = Spinner.class.getDeclaredField("mPopup");
//                        } catch (NoSuchFieldException e) {
//                            e.printStackTrace();
//                        }
//                        popup.setAccessible(true);
//
//                        // Get private mPopup member variable and try cast to ListPopupWindow
//                        android.widget.ListPopupWindow popupWindow = null;
//                        try {
//                            popupWindow = (android.widget.ListPopupWindow) popup.get(spinner);
//                        } catch (IllegalAccessException e) {
//                            e.printStackTrace();
//                        }
//
//                        // Set popupWindow height to 500px
//                        popupWindow.setHeight(dpToPx(50));
////                        spinner.setDropDownVerticalOffset(-dpToPx(100));
//                        //将可选内容与ArrayAdapter连接起来
//                        adapter = new ArrayAdapter<String>(Main2Activity.this,android.R.layout.simple_spinner_item,m);
//
//                        //设置下拉列表的风格
//                        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//
//                        //将adapter 添加到spinner中
//                        spinner.setAdapter(adapter);
//
//                        //添加事件Spinner事件监听
//                        spinner.setOnItemSelectedListener(new Main2Activity.SpinnerSelectedListener());
//
//                        //设置默认值
//                        spinner.setVisibility(View.VISIBLE);
//                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
//                            spinner.setPopupBackgroundResource(R.drawable.radius_border2);
//                            spinner.setDropDownVerticalOffset(dpToPx(50));
//                        }
//                         RadioGroup radioGroup_gender;
//                        radioGroup_gender= (RadioGroup) window.findViewById(R.id.radioGroup_gender);
//                        radioGroup_gender.setOnCheckedChangeListener();
                final Button bb1 = window.findViewById(R.id.b1);
                final Button bb2 = window.findViewById(R.id.b2);
                bb1.setBackground(drawable81);
                drawable81.setStroke(3, 0xff0000aa);
                drawable81.setColor(0x11000099);
                bb1.setTextColor(0xff000099);
                bb2.setBackground(drawable71);
                int cl2[] = new int[2];
                Button yes = window.findViewById(R.id.yes);
                yes.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (aa == 1)
                            fla = 1;
                        ifcolor[aa] = 1;
                        ff1[0] = 1;
                        if (ff[0] == 0) {
                            setloc(aa, 1);
                            for (int i = 0; i < 4; i++) {
                                loc[aa][2][i] = loc0[aa][2][i];
                            }
                        } else {
                            setloc(aa, 2);
                            for (int i = 0; i < 4; i++) {
                                loc[aa][1][i] = loc0[aa][1][i];
                            }
                        }
                        colorcan[aa][1] = c1[0];
                        colorcan[aa][2] = c1[1];
                        grcolor[aa] = grcolor0[aa];
                        dlg[2].cancel();
                    }
                });
                Button no = window.findViewById(R.id.no);
                no.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dlg[2].cancel();
                    }
                });
                bb1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (ff[0] == 1) {
                            setloc0(aa, 2);
                        }
                        ff[0] = 0;
                        useloc0(aa, 1);
                        drawable81.setStroke(3, 0xff0000aa);
                        drawable81.setColor(0x11000099);
                        bb1.setTextColor(0xff000099);
                        drawable71.setStroke(3, 0xffeeeeee);
                        bb2.setTextColor(0xff000000);
                        drawable71.setColor(0xffffffff);
                    }
                });
                bb2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (ff[0] == 0) {
                            setloc0(aa, 1);
                        }
                        useloc0(aa, 2);
                        ff[0] = 1;
                        drawable71.setStroke(3, 0xff0000aa);
                        drawable71.setColor(0x11000099);
                        bb2.setTextColor(0xff000099);
                        drawable81.setStroke(3, 0xffeeeeee);
                        bb1.setTextColor(0xff000000);
                        drawable81.setColor(0xffffffff);
                    }
                });
                ColorPickerViewa colorPicker = window.findViewById(R.id.opp);
                colorPicker.setOnColorChangeListener(new OnColorChangeListener() {
                    @Override
                    public void colorChanged(int color) {
                        // if(f==1)tvTest.setBackgroundColor(color);else
                        //te.setBackgroundColor(color);
//                                vLocationLayoutParams = (RelativeLayout.LayoutParams) vLocation.getLayoutParams();
//                                vLocationLayoutParams.leftMargin = 100;
//                                vLocationLayoutParams.topMargin = 100;
//                                vLocation.setLayoutParams(vLocationLayoutParams);
                        switch (aa) {
                            case 1:
                                if (ff[0] == 0) {
                                    c1[0] = color;
                                    if (rf[0] == 2)
                                        c1[1] = (c1[1] & 0x00FFFFFF) | (c1[0] & 0xFF000000);
                                    else if (rf[0] == 3)
                                        c1[1] = (c1[1] & 0xFF000000) | (c1[0] & 0x00FFFFFF);
                                    int a[] = {c1[0], c1[1]};
                                    layout.setBackground(drawable211);
                                    drawable211.setColors(a);
                                    drawable211.setOrientation(or[grcolor0[aa]]);
                                } else {
                                    c1[1] = color;
                                    if (rf[0] == 2)
                                        c1[0] = (c1[0] & 0x00FFFFFF) | (c1[1] & 0xFF000000);
                                    else if (rf[0] == 3)
                                        c1[0] = (c1[0] & 0xFF000000) | (c1[1] & 0x00FFFFFF);
                                    int b[] = {c1[0], c1[1]};
                                    layout.setBackground(drawable211);
                                    drawable211.setColors(b);
                                    drawable211.setOrientation(or[grcolor0[aa]]);
                                }
                                break;
                            case 2:
                                sh = color;
                                int c[] = {c1[0], c1[1]};
                                if (ff[0] == 0) {
                                    c1[0] = color;
                                    if (rf[0] == 2)
                                        c1[1] = (c1[1] & 0x00FFFFFF) | (c1[0] & 0xFF000000);
                                    else if (rf[0] == 3)
                                        c1[1] = (c1[1] & 0xFF000000) | (c1[0] & 0x00FFFFFF);
                                    c[0] = c1[0];
                                    c[1] = c1[1];
                                } else {
                                    c1[1] = color;
                                    if (rf[0] == 2)
                                        c1[0] = (c1[0] & 0x00FFFFFF) | (c1[1] & 0xFF000000);
                                    else if (rf[0] == 3)
                                        c1[0] = (c1[0] & 0xFF000000) | (c1[1] & 0x00FFFFFF);
                                    int b[] = {c1[0], c1[1]};
                                    c[0] = c1[0];
                                    c[1] = c1[1];
                                }
                                for (int o = 1; o < 26; o++) {
                                    if (str1[o].equals("")) {
                                    } else {
                                        drawable1[o - 1].setColors(c);
                                        drawable1[o - 1].setOrientation(or[grcolor0[aa]]);
                                    }
                                }
                                break;
//                            case 0:
////                                LinearGradient topToBottomLG = new LinearGradient(0, 0, 0, y1,color, 0xFF00FFFF, Shader.TileMode.REPEAT);//从上到下渐变
//                                for (int o = 1; o < 26; o++) {
//                                    if (str1[o].equals("")) {
//                                    } else {
//                                        te1 = findViewById(id2[o - 1]);
////                                        te1.getPaint().setShader(topToBottomLG);
//                                        te1.setText(getRadiusGradientSpan("我我我我我我我\n我我我我我我我我\n我我我我我我我", color, 0xFF00FFFF));
//                                        //  te1.invalidate();
////                                        te1.setTextColor(color);
//                                    }
//                                }
//                                break;
                        }


//layout.setBackgroundColor(color);
                    }
                });
            }
        });

    }
    private void getcrwid(Uri uri1){
        String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/files";
        File fil = new File(strFilePath, "landx1.png");
//        String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file";
//        File file = new File(strFilePath, "ll.png");//在创建文件
        Uri uri = FileProvider.getUriForFile(this, "com.lan.schedule.fileprovider", fil);

        Intent intent = new Intent();
        intent.setAction("com.android.camera.action.CROP");//Pick an item from the data
//        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION|Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        intent.setDataAndType(uri1, "image/*");//从所有图片中进行选择
        intent.putExtra("crop", "true");//设置为裁切
        intent.putExtra("aspectX", 344);//裁切的宽比例
        intent.putExtra("aspectY", 256);//裁切的高比例
        intent.putExtra("outputX", 2016);//裁切的宽度
        intent.putExtra("outputY", 1500);//裁切的高度
        intent.putExtra("scale", true);//支持缩放
        intent.putExtra("return-data", false);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);//将裁切的结果输出到指定的Uri
        intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//裁切成的图片的格式
        intent.putExtra("noFaceDetection", true); // no face detection
        List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        for (ResolveInfo resolveInfo : resInfoList) {
            //我用的小米手机 packageName 得到的是：com.miui.gallery
            String packageName = resolveInfo.activityInfo.packageName;
            grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
            //注意不是 getPackageName()！！ getPackageName()得到的是app的包名
//            grantUriPermission(getPackageName(), cropUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }
        ComponentName componentName = intent.resolveActivity(getPackageManager());
        if (componentName != null) {
            startActivityForResult(intent, 88667);
        }
    }
    private void cropFromGallerywid(){
        String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/files";
        File fil = new File(strFilePath, "landx1.png");
//        String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file";
//        File file = new File(strFilePath, "ll.png");//在创建文件
//        Uri uri = FileProvider.getUriForFile(this, "com.lan.schedule.fileprovider", fil);
        Intent inl = new Intent(Intent.ACTION_PICK, null);
        inl.setDataAndType(MediaStore.Images.Media.INTERNAL_CONTENT_URI, "image/*");
//        inl.putExtra(MediaStore.EXTRA_OUTPUT, uri);//将裁切的结果输出到指定的Uri
//        inl.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//裁切成的图片的格式
//        inl.putExtra("noFaceDetection", true); // no face detection
        startActivityForResult(inl, 871566);
        // TODO Auto-generated method stub
//        String stri= String.valueOf(imageUri);
//        System.out.println(stri);
//System.out.println(uri);
//        Intent intent = new Intent();
//        intent.setAction("com.android.camera.action.CROP");//Pick an item from the data
//        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION|Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
//        intent.setDataAndType(uri,"image/*");//从所有图片中进行选择
////        intent.putExtra("crop", "true");//设置为裁切
////        intent.putExtra("aspectX", 344);//裁切的宽比例
////        intent.putExtra("aspectY", 256);//裁切的高比例
////        intent.putExtra("outputX", 344);//裁切的宽度
////        intent.putExtra("outputY", 256);//裁切的高度
////        intent.putExtra("scale", true);//支持缩放
////        intent.putExtra("return-data", false);
//        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);//将裁切的结果输出到指定的Uri
//        intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//裁切成的图片的格式
//        intent.putExtra("noFaceDetection", true); // no face detection
//        startActivityForResult(intent, SELECT_PIC);
    }
    public static int verificationCode() {
        //生成六位随机正整数
        Random random = new Random();
        String verificationCode = String.valueOf(random.nextInt(9) + 1);
        for (int i = 0; i < 5; i++) {
            verificationCode += random.nextInt(10);
        }
        return Integer.parseInt(verificationCode);
    }
    public static void uploadManage(File uploadFile,String id){
        String boundary = "*****";
        try {
            URL url = new URL("http://43.139.192.56:8080/Demo/upl");//你的服务器地址
            HttpURLConnection con = (HttpURLConnection)url.openConnection();

            // 允许Input、Output，不使用Cache
            con.setDoInput(true);
            con.setDoOutput(true);
            con.setUseCaches(false);

            con.setConnectTimeout(50000);
            con.setReadTimeout(50000);
            // 设置传送的method=POST
            con.setRequestMethod("POST");
            //在一次TCP连接中可以持续发送多份数据而不会断开连接
            con.setRequestProperty("Connection", "Keep-Alive");
            //设置编码
            con.setRequestProperty("Charset", "UTF-8");
            //text/plain能上传纯文本文件的编码格式
            con.setRequestProperty("Content-Type", "text/plain");
            con.setRequestProperty("filename",id+".jpg");
            // 设置DataOutputStream
            DataOutputStream ds = new DataOutputStream(con.getOutputStream());

            // 取得文件的FileInputStream
            FileInputStream fStream = new FileInputStream(uploadFile);
            // 设置每次写入1024bytes
            int bufferSize = 1024;
            byte[] buffer = new byte[bufferSize];

            int length = -1;
            // 从文件读取数据至缓冲区
            while ((length = fStream.read(buffer)) != -1) {
                // 将资料写入DataOutputStream中
                ds.write(buffer, 0, length);
            }
            ds.flush();
            fStream.close();
            ds.close();
            if(con.getResponseCode() == 200){
                System.out.println("文件上传成功！上传文件为：" + uploadFile);
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("Http","报错信息toString：" + e.toString());
            System.out.println("文件上传失败！上传文件为：" + uploadFile);
            System.out.println("报错信息toString：" + e.toString());
        }
    }
    public void sharecode(View view) {
        String data = null;
        data = fla + ":" + alp + ":";
        for (int y = 0; y < 6; y++) {
            data = data + ifcolor[y] + ":" + grcolor[y] + ":";
            for (int x = 0; x < 3; x++) {
                data = data + colorcan[y][x] + ":";
            }
        }
        data =data+flazjm+":"+vpa+":";

                ObjectMapper mapper = new ObjectMapper();
int sharecode=verificationCode();
                FutureTask signUpTask = new FutureTask<>(new NetworkThread(sharecode,data,NetworkSettings.COLOR_ADD));

                Thread thread = new Thread(signUpTask);

                thread.start();

                try{

                    ResponseBody body = mapper.readValue(String.valueOf(signUpTask.get()),ResponseBody.class);

                    Toast.makeText(getApplicationContext(),body.getCode() == 200 ? "分享成功，可复制下方id发送其他人" : "分享失败",Toast.LENGTH_SHORT).show();

                }catch (Exception e){

                    e.printStackTrace();

                }
                String strcode= String.valueOf(sharecode);
                if(fla==2){
                    String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/files";
                    File fil=   new File(strFilePath, "landx.png");
                    new Thread(){
                        @Override
                        public void run() {
                            uploadManage(fil,strcode);
                        }
                    }.start();
                }
        sharet.append(strcode);
    }

    //    View inflatedView = getLayoutInflater().inflate(R.layout.ct1, null);
//    RadioButton text =  inflatedView.findViewById(R.id.f1);    //通过另外一个布局对象的findViewById获取其中的控件
//    RadioButton text1 =  inflatedView.findViewById(R.id.f2);    //通过另外一个布局对象的findViewById获取其中的控件
//
//    public void onCheckedChanged(RadioGroup group, int checkedId) {
////得到用户选中的 RadioButton 对象
//RadioButton radioButton_checked= (RadioButton) group.findViewById(checkedId);
//String gender=radioButton_checked.getText().toString();
////Toast.makeText(this,gender,Toast.LENGTH_LONG).show();
//switch (checkedId){
//case text.getId():
////当用户点击男性按钮时执行的代码
//System.out.println("===男性===");
//break;
//case text1.getId():
////当用户点击女性按钮时执行的代码
//System.out.println("===女性===");
//break;
//}
//System.out.println("===onCheckedChanged(RadioGroup group="+group+", int checkedId="+checkedId+")==");
//}
    class SpinnerSelectedListener implements AdapterView.OnItemSelectedListener {

        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
                                   long arg3) {
            or1 = or[arg2];
            drawable211.setOrientation(or1);
//            make(0,arg2+1);
        }

        public void onNothingSelected(AdapterView<?> arg0) {
            // make1(bben);
        }
    }

    @SuppressLint("WrongConstant")
    public void onProgressChang12(int progressColor) {
        red = 0;
        green = 0;
        blue = 0;
        index = (int) (progressColor / (100 / 6F));
        float v = progressColor % (100 / 6F) / (100 / 6F);
        switch (index) {
            case 0: //红<-->中--绿
                red = 255;
                green = (int) (255 * v);
                break;
            case 1://红--中<-->绿
                red = (int) (255 * (1 - v));
                green = 255;
                break;
            case 2: //绿<-->中--蓝
                green = 255;
                blue = (int) (255 * v);
                break;
            case 3://绿--中<-->蓝
                green = (int) (255 * (1 - v));
                blue = 255;
                break;
            case 4: //蓝<-->中--红
                blue = 255;
                red = (int) (255 * v);
                break;
            case 5://蓝--中<-->红
                blue = (int) (255 * (1 - v));
                red = 255;
                break;
            default:
                red = 255;
                break;
        }
        //changeColor();
        GradientDrawable drawable1 = new GradientDrawable();
        drawable1.setShape(GradientDrawable.RECTANGLE);
        drawable1.setGradientType(GradientDrawable.RECTANGLE);
        drawable1.setCornerRadius(30);
        drawable1.setColor(Color.rgb(red, green, blue));
        ColorPickerViewa.vBgColor.setBackground(drawable1);
        int tempRed = red;
        int tempGreen = green;
        int tempBlue = blue;
        float hPercent = 1 - (ColorPickerViewa.vLocation.getX() / (ColorPickerViewa.vBgColor.getWidth() - ColorPickerViewa.vLocation.getWidth()));
        float vPercent = ColorPickerViewa.vLocation.getY() / (ColorPickerViewa.vBgColor.getHeight() - ColorPickerViewa.vLocation.getHeight());
        switch (index) {
            case 0:
                tempGreen = (int) (green + hPercent * (255 - green));
                tempBlue = (int) (blue + hPercent * (255 - blue));
                break;
            case 1:
                tempRed = (int) (red + hPercent * (255 - red));
                tempBlue = (int) (blue + hPercent * (255 - blue));
                break;
            case 2:
                tempRed = (int) (red + hPercent * (255 - red));
                tempBlue = (int) (blue + hPercent * (255 - blue));
                break;
            case 3:
                tempRed = (int) (red + hPercent * (255 - red));
                tempGreen = (int) (green + hPercent * (255 - green));
                break;
            case 4:
                tempRed = (int) (red + hPercent * (255 - red));
                tempGreen = (int) (green + hPercent * (255 - green));
                break;
            case 5:
            case 6:
                tempGreen = (int) (green + hPercent * (255 - green));
                tempBlue = (int) (blue + hPercent * (255 - blue));
                break;
        }
        tempRed = (int) (tempRed - tempRed * vPercent);
        tempGreen = (int) (tempGreen - tempGreen * vPercent);
        tempBlue = (int) (tempBlue - tempBlue * vPercent);
        int[] gradientColor = {Color.rgb(tempRed, tempGreen, tempBlue), Color.argb(0xFF, 0, 0, 0)};
        GradientDrawable drawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, gradientColor);
        ColorPickerViewa.vTransPreview.setBackground(drawable);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        switch (requestCode) {
            case SELECT_PIC:
                if (resultCode == RESULT_OK) {
//                    Bitmap bp=data.getParcelableExtra("data");
//                    int src_w = bp.getWidth();
//                    int src_h = bp.getHeight();
//                    float scale_w = ((float) 2016) / src_w;
//                    float scale_h = ((float) 1500) / src_h;
//                    Matrix matrix = new Matrix();
//                    matrix.postScale(scale_w, scale_h);
//                    Bitmap bihuanbmp = Bitmap.createBitmap(bp, 0, 0, src_w, src_h, matrix,true);
//                    File cf = new File(String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file", "lan.png");
//                    FileOutputStream fos = null;
//                    try {
//                        fos = new FileOutputStream(cf);
//                    } catch (FileNotFoundException e) {
//                        e.printStackTrace();
//                    }
//                    bihuanbmp.compress(Bitmap.CompressFormat.PNG, 100, fos);
//                    try {
//                        fos.close();
//                    } catch (IOException e) {
//                        e.printStackTrace();
//                    }
//                    float scale_w1 = ((float) 340) / src_w;
//                    float scale_h1 = ((float) 253) / src_h;
//                    Matrix matrix1 = new Matrix();
//                    matrix1.postScale(scale_w1, scale_h1);
//                    Bitmap bihuanbmp1 = Bitmap.createBitmap(bp, 0, 0, src_w, src_h, matrix1,true);
//                    File cf1 = new File(String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file", "lanbx.png");
//                    FileOutputStream fos1 = null;
//                    try {
//                        fos1 = new FileOutputStream(cf1);
//                    } catch (FileNotFoundException e) {
//                        e.printStackTrace();
//                    }
//                    bihuanbmp1.compress(Bitmap.CompressFormat.PNG, 100, fos1);
//                    try {
//                        fos1.close();
//                    } catch (IOException e) {
//                        e.printStackTrace();
//                    }
//                    ma(100);
                    try {
                        bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                    int src_w = bitmap.getWidth();
                    int src_h = bitmap.getHeight();
                    float scale_w1 = ((float) 340) / src_w;
                    float scale_h1 = ((float) 253) / src_h;
                    Matrix matrix1 = new Matrix();
                    matrix1.postScale(scale_w1, scale_h1);
                    Bitmap bihuanbmp1 = Bitmap.createBitmap(bitmap, 0, 0, src_w, src_h, matrix1,true);
                    File cf1 = new File(String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file", "lanbx.png");
                    FileOutputStream fos1 = null;
                    try {
                        fos1 = new FileOutputStream(cf1);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                    bihuanbmp1.compress(Bitmap.CompressFormat.PNG, 100, fos1);
                    try {
                        fos1.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    fla = 2;
                    bbb = new BitmapDrawable(toRoundCorner(bitmap, 100));
                    LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
                    layout.setBackgroundDrawable(bbb);
                }
                break;
            case 88667:
                if (resultCode == RESULT_OK) {
                    String data1 = "20";
                    String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/file/th";
                    File cacheFile = new File(strFilePath);
                    // 上级文件不存在，进行文件夹的创建
                    if (!cacheFile.exists()) { // 先根据路径创建文件夹
                        cacheFile.mkdirs();
                    }
                    String filename = "th2.txt";
                    File file = new File(strFilePath, filename);//在创建文件
                    boolean createResult = false;
                    try {
                        if (file.exists()) {
                            file.delete();
                        }
                        createResult = file.createNewFile();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    file.canWrite();
                    OutputStream ff = null;
                    try {
                        ff = new FileOutputStream(file);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                    byte[] szBuf = data1.getBytes();
                    try {
                        ff.write(szBuf);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    try {
                        ff.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                break;
            case 8715:
//                String stry= String.valueOf(getImageContentUri(new File(getRealFilePath(data.getData()))));
//                edit.setText(stry+"666");
                getcr(getImageContentUri(new File(getRealFilePath(data.getData()))));
                break;
            case 871566:
                getcrwid(data.getData());
                break;
            case 8716:
                getcrzjm(getImageContentUri(new File(getRealFilePath(data.getData()))));
                break;
            case 8717:
                flazjm=9;
                break;
            case 55500:
                if (resultCode == RESULT_OK) {
                    Uri uri = data.getData();
                    ContentResolver cr = this.getContentResolver();
                    /** 数据库查询操作。
                     * 第一个参数 uri：为要查询的数据库+表的名称。
                     * 第二个参数 projection ： 要查询的列。
                     * 第三个参数 selection ： 查询的条件，相当于SQL where。
                     * 第三个参数 selectionArgs ： 查询条件的参数，相当于 ？。
                     * 第四个参数 sortOrder ： 结果排序。
                     */
                    Cursor cursor = cr.query(uri, null, null, null, null);
                    if (cursor != null) {
                        if (cursor.moveToFirst()) {
                            flazjm=10;
                            fla=-100;
                            // 视频ID:MediaStore.Audio.Media._ID
                            int videoId = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID));
                            // 视频名称：MediaStore.Audio.Media.TITLE
                            String title = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.TITLE));
                            // 视频路径：MediaStore.Audio.Media.DATA
                            vpa = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA));
                            // 视频时长：MediaStore.Audio.Media.DURATION
                            int duration = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION));
                            // 视频大小：MediaStore.Audio.Media.SIZE
                            long size = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE));

                            // 视频缩略图路径：MediaStore.Images.Media.DATA
                            String imagePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
                            // 缩略图ID:MediaStore.Audio.Media._ID
                            int imageId = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID));
                            // 方法一 Thumbnails 利用createVideoThumbnail 通过路径得到缩略图，保持为视频的默认比例
                            // 第一个参数为 ContentResolver，第二个参数为视频缩略图ID， 第三个参数kind有两种为：MICRO_KIND和MINI_KIND 字面意思理解为微型和迷你两种缩略模式，前者分辨率更低一些。
                            Bitmap bitmap1 = MediaStore.Video.Thumbnails.getThumbnail(cr, imageId, MediaStore.Video.Thumbnails.MICRO_KIND, null);

                            // 方法二 ThumbnailUtils 利用createVideoThumbnail 通过路径得到缩略图，保持为视频的默认比例
                            // 第一个参数为 视频/缩略图的位置，第二个依旧是分辨率相关的kind
                            Bitmap bitmap2 = ThumbnailUtils.createVideoThumbnail(imagePath, MediaStore.Video.Thumbnails.MICRO_KIND);
                            // 如果追求更好的话可以利用 ThumbnailUtils.extractThumbnail 把缩略图转化为的制定大小
//                        ThumbnailUtils.extractThumbnail(bitmap, width,height ,ThumbnailUtils.OPTIONS_RECYCLE_INPUT);

                        }
                        cursor.close();
                    }
                }
                break;
            default:
                break;
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    public void set2(final int fff) {
        final int[] ff1 = {0};
        final int[] cl0 = new int[1];
        cl0[0] = colorcan[fff][0];
        final int[] cs = {colorcan[1][0], colorcan[1][0]};
        final int[] cs1 = {colorcan[2][0], colorcan[2][0]};
        dlg[1] = new AlertDialog.Builder(Main2Activity.this).create();
        dlg[1].setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialogInterface) {
                System.out.println("000" + cl0[0]);

                if (ff1[0] == 1) {
                    setloc(fff, 0);
                    colorcan[fff][0] = cl0[0];
                    System.out.println("000" + cl0[0]);
                } else {
                    System.out.println("111" + cl0[0]);

                    switch (fff) {
                        case 3: {
                            for (int o = 1; o < 26; o++) {
                                if (str1[o].equals("")) {
                                } else {
                                    drawable1[o - 1].setStroke(3, colorcan[3][0]);
                                }
                            }
                        }
                        break;
                        case 1: {
                            if (fla == 1) {
                                if (ifcolor[1] == 0)
                                    drawable211.setColor(colorcan[1][0]);
                                else {
                                    int[] colors = {colorcan[1][1], colorcan[1][2]};
                                    drawable211.setColors(colors);
                                    drawable211.setOrientation(or[grcolor[1]]);
                                }
                                layout.setBackgroundDrawable(drawable211);
                            } else if (fla == 2) {
                                Uri imageUri;
                                String strFilePath = String.valueOf(Environment.getExternalStorageDirectory()) + "/Android/data/com.lan.schedule/files";
                                imageUri = Uri.fromFile(new File(strFilePath, "landx.png"));
                                try {
                                    bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
                                } catch (FileNotFoundException e) {
                                    e.printStackTrace();
                                }
//                                bitmap = getAlplaBitmap(bitmap, alp);
                                bbb = new BitmapDrawable(toRoundCorner(bitmap, 100));
                                layout.setBackgroundDrawable(bbb);
                            } else {
                                layout.setBackgroundDrawable(bbb);
                            }
                        }
                        break;
                        case 2: {
                            if (ifcolor[2] == 0) {
                                for (int o = 1; o < 26; o++) {
                                    if (str1[o].equals("")) {
                                    } else {
                                        drawable1[o - 1].setColors(cs1);
                                    }
                                }
                            } else {
                                int cs2[] = {colorcan[2][1], colorcan[2][2]};
                                for (int o = 1; o < 26; o++) {
                                    if (str1[o].equals("")) {
                                    } else {
                                        drawable1[o - 1].setColors(cs2);
                                        drawable1[o - 1].setOrientation(or1);
                                    }
                                }
                            }
                        }
                        break;
                        case 0:
                            if (ifcolor[0] == 0) {
                                for (int o = 1; o < 26; o++) {
                                    if (str1[o].equals("")) {
                                    } else {
                                        te1 = findViewById(id2[o - 1]);
                                        te1.setTextColor(colorcan[0][0]);
                                    }
                                }
                            } else {
                                for (int o = 1; o < 26; o++) {
                                    if (str1[o].equals("")) {
                                    } else {
                                        te1 = findViewById(id2[o - 1]);
//                                        te1.getPaint().setShader(topToBottomLG);
                                        te1.setText(getRadiusGradientSpan(str1[o], colorcan[0][1], colorcan[0][2]));
                                        //  te1.invalidate();
//                                        te1.setTextColor(color);
                                    }
                                }
                            }
                            break;
                        default:
                            break;
                    }
                }
            }
        });
        dlg[1].show();//显示对话框
        Window window = dlg[1].getWindow();//获取对话框窗口
        window.setGravity(Gravity.BOTTOM);//设置对话框显示剧中的位置
        window.setContentView(R.layout.ct);//设置对话框布局
        window.setBackgroundDrawable(dr);
        WindowManager.LayoutParams params = dlg[1].getWindow()
                .getAttributes();

        Display display = getWindowManager().getDefaultDisplay();
        params.width = (int) (display.getWidth());
//                        params.width=dpToPx(360);
        params.dimAmount = 0.0f;
        dlg[1].getWindow().setAttributes(params);
        useloc(fff, 0);
        Button yes = window.findViewById(R.id.yes);
        yes.setOnClickListener(new View.OnClickListener() {
            @Override

            public void onClick(View view) {
                ifcolor[fff] = 0;
                ff1[0] = 1;
                if (fff == 1) fla = 1;
                dlg[1].cancel();
            }
        });
        Button no = window.findViewById(R.id.no);
        no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dlg[1].cancel();
            }
        });
        ColorPickerViewa colorPicker = window.findViewById(R.id.opp);
        final int[] flag = {0};
       // colorPicker.onProgressChanged((ColorPickerViewa.vColorBar.getHeight()/ColorPickerViewa.llColorProgress.getHeight())*100);
colorPicker.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                // TODO Auto-generated method stub
                if(flag[0]==0){
                    System.out.println(ColorPickerViewa.colorBarLayoutParams.topMargin+"----"+ColorPickerViewa.llColorProgress.getHeight());
                colorPicker.onProgressChanged(100-(int)(((float)ColorPickerViewa.colorBarLayoutParams.topMargin/(float) ColorPickerViewa.llColorProgress.getHeight())*100));
                flag[0] =1;}
            }
        });

        colorPicker.setOnColorChangeListener(new OnColorChangeListener() {
            @Override
            public void colorChanged(int color) {
                cl0[0] = color;
                // if(f==1)tvTest.setBackgroundColor(color);else
                //te.setBackgroundColor(color);
                int c[] = {color, color};
                switch (fff) {
                    case 3: {
                        for (int o = 1; o < 26; o++) {
                            if (str1[o].equals("")) {
                            } else {
                                drawable1[o - 1].setStroke(3, color);
                            }
                        }
                    }
                    break;
                    case 1: {
                        layout.setBackground(drawable211);
                        drawable211.setColors(c);
                    }
                    break;
                    case 2: {
                        sh = color;
                        for (int o = 1; o < 26; o++) {
                            if (str1[o].equals("")) {
                            } else {
                                drawable1[o - 1].setColors(c);
                            }
                        }
                    }
                    break;
                    case 0:
                        fo = color;
                        for (int o = 1; o < 26; o++) {
                            if (str1[o].equals("")) {
                            } else {
                                te1 = findViewById(id2[o - 1]);
                                te1.setTextColor(color);
                            }
                        }
                        break;
                    default:
                        break;
                }
//layout.setBackgroundColor(color);
            }
        });
    }

    private void ma(int p) {
        try {
            bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        Bitmap b2 = getAlplaBitmap(bitmap, p);
        bbb = new BitmapDrawable(toRoundCorner(b2, 100));
        LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
        layout.setBackgroundDrawable(bbb);
    }
}
